package com.lei.day1rikao;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.lei.day1rikao.contract.LoginContract;
import com.lei.day1rikao.model.LoginModel;
import com.lei.day1rikao.presenter.LoginPresenter;
import com.lei.mvpdemo.view.BaseActivty;

import java.util.HashMap;

public class MainActivity extends BaseActivty<LoginPresenter> implements LoginContract.View {
    private EditText etNameLogin;
    private EditText etPwdLogin;
    private Button btLogin;
    private LoginPresenter loginPresenter;


    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public int bindlayout() {
        return R.layout.activity_main;
    }

    @Override
    public void initview() {
        etNameLogin = (EditText) findViewById(R.id.et_name_login);
        etPwdLogin = (EditText) findViewById(R.id.et_pwd_login);
        btLogin = (Button) findViewById(R.id.bt_login);
        btLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name = etNameLogin.getText().toString().trim();
                String pwd = etPwdLogin.getText().toString().trim();
                HashMap<String, String> map = new HashMap<>();
                map.put("name",name);
                map.put("pwd",pwd);
                if (name.length()<8){
                    if (!pwd.equals(null)){
                        loginPresenter.log(map);
                    }
                }
            }
        });
    }

    @Override
    public void inject() {
        loginPresenter = new LoginPresenter(new LoginModel(),this);
    }

    @Override
    public void showmsg(String msg) {
        super.showmsg(msg);
        Toast.makeText(this, ""+msg, Toast.LENGTH_SHORT).show();
    }

}
